//
//  FooterOwnerInfoView.m
//  PhongThuyHuongNha
//
//  Created by Le Anh Tai on 10/16/13.
//  Copyright (c) 2013 Le Anh Tai. All rights reserved.
//

#import "FooterResultView.h"
#import "UIConstants.h"

@implementation FooterResultView

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    
    if (self)
    {
        self.backgroundColor = [UIColor redColor];
        _webView = [[UIWebView alloc] init];
        _webView.backgroundColor = [UIColor whiteColor];
        _webView.opaque = NO;
        _webView.delegate = self;
        _webView.userInteractionEnabled = YES;
        _webView.scrollView.scrollEnabled = NO;

        [self addSubview:_webView];
        [_webView stringByEvaluatingJavaScriptFromString:@""];
        NSString *filePath=[[NSBundle mainBundle]pathForResource:@"diengiai" ofType:@"html" inDirectory:nil];
        [_webView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:filePath]]];
    }
    return self;
}

-(void)webViewDidFinishLoad:(UIWebView *)webView
{
    float heightBody = [[webView stringByEvaluatingJavaScriptFromString:@"document.body.scrollHeight;"] floatValue];
    if (SCREEN_SIZE.height == 480)
    {
        self.height = heightBody + 450;
    }
    else
    {
        self.height = heightBody + 600;
    }
    
}

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
    if (navigationType == UIWebViewNavigationTypeLinkClicked)
    {
        if ([_delegate respondsToSelector:@selector(footerResultViewDidPressLink:)])
        {
            [_delegate footerResultViewDidPressLink:self];
        }
        
        return NO;
    }
    
    return YES;
}

- (void)setFrame:(CGRect)frame
{
    [super setFrame:frame];
    [_webView setFrame:self.bounds];
}

@end
